package cn.db.tools.dbtools;

import cn.db.tools.dbtools.message.ToastMessage;
import com.google.common.hash.Hashing;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import org.pomo.toasterfx.model.impl.ToastTypes;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

public class HelloController implements Initializable {

    @FXML
    TabPane modelTabPane;

    @FXML
    Menu crypt;

    private Map<String, Tab> tabMapCache = new HashMap<>();


    @Override
    public void initialize(URL location, ResourceBundle resources) {
    }

    @FXML
    public void selectMenuItem(ActionEvent event) {

        String id = ((MenuItem) event.getTarget()).getId();

        try {

            if (!tabMapCache.containsKey(id)) {
                Tab tab = new Tab(((MenuItem) event.getTarget()).getText());
                FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("/cn/db/tools/dbtools/model/" + id + ".fxml"));
                tab.setContent(fxmlLoader.load());
                modelTabPane.getTabs().add(tab);
                tabMapCache.put(id, tab);
            } else {
                modelTabPane.getTabs().add(tabMapCache.get(id));
            }

            modelTabPane.getSelectionModel().select(tabMapCache.get(id));

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
